function requetData() {
    $.ajax({
        url:"/game/gamelist" ,
        dataType:"json",
        type:"get",
        success:function (data) {
            console.log(data)
            showData(data)
        }
    })
}
function choose(gameId) {
    var friendUserId = location.search.match(new RegExp("[\?\&]friendUserId=([^\&]+)", "i"))[1];
    console.log(friendUserId)
    $.ajax({
        url: "/friendlist/givegame",
        data: "friendUserId=" + friendUserId +"&gameId="+ gameId,
        //dataType: "json",
        type: "post",
        success: function (data) {
            if (data == "success") {
                alert("赠送成功")
                setTimeout(function () {
                    location.href = "/friendlist.jsp"
                }, 1000)
            }
        }
    })
}
function  showData(jsonObj) {
    var html = ' <tr><th>游戏截图</th><th>游戏名称</th><th>游戏价格</th><th>游戏介绍</th><th>操作</th></tr>'

    for(var i = 0; i < jsonObj.length; i ++) {
        html = html + "<tr><td class='tdclass'>"
        html = html +"<img src='" + jsonObj[i].gamePicture +"' height=100px width=180px ></img>"
        html = html + "</td><td>"
        html = html + jsonObj[i].gameName
        html = html + "</td><td>"
        html = html + jsonObj[i].gamePrice
        html = html + "</td><td>"
        html = html + jsonObj[i].gameIntroduction
        html = html + "</td>"
        html = html + "<td><button  class='btnv6_blue_hoverfade  btn btn-primary btn-sm' onclick='choose(" + jsonObj[i].gameId + ")'>选择</button></td>"
        html = html + "</tr>"

    }

    $('.table').html(html)
}

requetData();

